home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c,comp.lang.objective-c
- Subject: Re: Comma Delimited function wanted
- Date: Thu, 11 Jan 1996 13:19:43 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d3360$kg3@tahko.lpr.carel.fi>
- References: <4d1l42$mb6@voyager.Internex.NET>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- ian_stewart@nyro.com (Ian H. Stewart) wrote:
-
- >Help with a comma delimited function needed.
-
- >I did this once before, but I am blocked and can't
- >find the original source.
-
- >Here is what I need to do:
-
- >I have a buffer full of text.
-
- >char buffer = "3740067099,914885AC2,P03,5000";
-
- >I have four char vars to put this into.
-
- >char field1[20], field2[20], field3[20], field4[20];
-
- >What I want to do is get this as the end result.
-
-
- >field1 = 3740067099
- >field2 = 914885AC2
- >field3 = P03
- >field4 = 5000
-
-
- >Anyway, help is appreciated.
-
- >ian
-
- Try something like this:
-
- char buffer[] = "1,2,3,4"; /* Just an example */
- char *p = buffer; /* points to begin of buf */
- char field[4][20];
- int i, j;
-
- for (j = 0; j < 4; j++) {
- memset(field[j], 0, sizeof(field[j])); /* Initialize to zeros */
- for (i = 0; i < sizeof(field[j]); i++, p++)
- if (*p == ',' || !*p) {
- field[j][i] = '\0';
- break;
- }
- else
- field[j][i] = *p;
- }
-
- Later,
- AriL
-
- All my opinions are mine and mine alone.
-
-